<?php
require_once './config.php';
header("Access-Control-Allow-Origin:*");

$key = $_REQUEST['key'];
$page = $_REQUEST['page'];
$size = $_REQUEST['size'];

$skip = ($page - 1) * $size;

$sql = "SELECT*from goodsinfo WHERE gname like '%$key%' LIMIT $skip,$size";

$result = mysqli_query($conn, $sql);

$obj = array(
    'code' => 1,
    'msg' => 'success',
);

$list = array();

while ($data = mysqli_fetch_array($result)) {
    $temp = array();
    $temp['gid'] = $data['gid'];
    $temp['goods_id'] = $data['goods_id'];
    $temp['price'] = $data['price'];
    $temp['gname'] = $data['gname'];
    // $temp['detail'] = $data['detail'];
    $temp['img'] = $data['img'];
    // $temp['imgs'] = $data['imgs'];
    $temp['desc'] = $data['desc'];
    $list[] = $temp;
}
$obj = array();
$obj['code'] = 1;
$obj['msg'] = 'success';
$obj['data'] = $list;

$sql = "SELECT count(*) from goodsinfo WHERE gname LIKE '%$key%'";

$result = mysqli_query($conn, $sql);

$data = mysqli_fetch_assoc($result);

$obj['count'] = $data['count(*)'];
echo json_encode(($obj));
